Follow-up r79845: add function documentation; only call wfMakeDirsParent if we have...
authorBryan Tong Minh <btongminh@users.mediawiki.org>
Sat, 8 Jan 2011 11:49:09 +0000 (11:49 +0000)
committerBryan Tong Minh <btongminh@users.mediawiki.org>
Sat, 8 Jan 2011 11:49:09 +0000 (11:49 +0000)
On r79845 I submitted a wrong commit summary, here is it for reference:

(bug 6672) Images are now autorotated according to their EXIF orientation. Following the Flickr example, this only affects thumbnails, with the source unrotated.

* Introduced BitmapHandler::canRotate() and BitmapHandler::getRotation() to check if rotation is supported and what the amount of rotation is
* Factored out scaler determination into BitmapHandler::getScalerType()
* ImageMagick uses the -auto-orientation option
* GD uses imagerotate()
* Unconditionally show the thumb size on the image page, don't know why this wasn't shown for SVGs etc.

includes/media/Bitmap.php

index c9ff9db..5d4de7e 100644 (file)
@@ -176,7 +176,7 @@ class BitmapHandler extends ImageHandler {
                        $scaler = 'client';
                }
                
-               if ( $scaler != 'client' ) {
+               if ( $scaler != 'client' && $dstPath ) {
                        if ( !wfMkdirParents( dirname( $dstPath ) ) ) {
                                # Unable to create a path for the thumbnail
                                return 'client';
@@ -647,6 +647,13 @@ class BitmapHandler extends ImageHandler {
                return $result;
        }
        
+       /**
+        * Try to read out the orientation of the file and return the angle that 
+        * the file needs to be rotated to be viewed
+        * 
+        * @param $file File
+        * @return int 0, 90, 180 or 270
+        */
        public function getRotation( $file ) {
                $data = $file->getMetadata();
                if ( !$data ) {
@@ -668,11 +675,23 @@ class BitmapHandler extends ImageHandler {
                }
                return 0;
        }
+       /**
+        * Returns whether the current scaler supports rotation (im and gd do)
+        * 
+        * @return bool
+        */
        public function canRotate() {
                $scaler = $this->getScalerType( null, false );
                return $scaler == 'im' || $scaler == 'gd';
        }
        
+       /**
+        * Rerurns whether the file needs to be rendered. Returns true if the 
+        * file requires rotation and we are able to rotate it.
+        * 
+        * @param $file File
+        * @return bool
+        */
        public function mustRender( $file ) {
                return $this->canRotate() && $this->getRotation( $file ) != 0;
        }